﻿using System;
using System.Text;
using System.Linq;
using System.Configuration;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Entities = Vision.Core.Entities;
using Components = Vision.Core.Components;

namespace Vision.Web.Service
{
    [ServiceContract(Namespace = "")]    
    public class VisionService
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="folderId"></param>
        /// <returns></returns>
        [OperationContract]
        public List<Entities.Activities.VisionActivity> GetVisionActivities(int folderId)
        {
            using (Components.ActivityCatalog activityCatalog = new Components.ActivityCatalog(ConfigurationManager.AppSettings["VisionCatalog"])){
                return activityCatalog.GetVisionActivities(folderId);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="activityId"></param>
        /// <returns></returns>
        [OperationContract]
        public Entities.Activities.VisionActivity GetVisionActivityFromCatalog(int activityId)
        {
            using (Components.ActivityCatalog activityCatalog = new Components.ActivityCatalog(ConfigurationManager.AppSettings["VisionCatalog"])){
                return activityCatalog.GetVisionActivityFromCatalog(activityId);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="enterpriseActivity"></param>
        [OperationContract]
        public void SaveVisionActivityToCatalog(Entities.Activities.VisionActivity enterpriseActivity)
        {
            using (Components.ActivityCatalog activityCatalog = new Components.ActivityCatalog(ConfigurationManager.AppSettings["VisionCatalog"])){
                activityCatalog.SaveVisionActivityToCatalog(enterpriseActivity);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="documentKey"></param>
        /// <returns></returns>
        [OperationContract]
        public Entities.Filing.Document GetVisionDocumentFromCatalog(Guid documentKey)
        {
            using (Components.ActivityCatalog activityCatalog = new Components.ActivityCatalog(ConfigurationManager.AppSettings["VisionCatalog"])){
                return activityCatalog.GetVisionDocumentFromCatalog(documentKey);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="document"></param>
        [OperationContract]
        public void SaveVisionDocumentToCatalog(Entities.Filing.Document document)
        {
            using (Components.ActivityCatalog activityCatalog = new Components.ActivityCatalog(ConfigurationManager.AppSettings["VisionCatalog"])){
                activityCatalog.SaveVisionDocumentToCatalog(document);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        public Entities.Filing.Folder GetFolders()
        {
            using (Components.ActivityCatalog activityCatalog = new Components.ActivityCatalog(ConfigurationManager.AppSettings["VisionCatalog"])){
                return activityCatalog.GetFolders();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="includeChildren"></param>
        /// <returns></returns>
        [OperationContract]
        public Entities.Filing.Folder GetFolderById(int Id, bool includeChildren)
        {
            using (Components.ActivityCatalog activityCatalog = new Components.ActivityCatalog(ConfigurationManager.AppSettings["VisionCatalog"])){
                return activityCatalog.GetFolderById(Id, includeChildren);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aqMessage"></param>
        [OperationContract]
        public void QueueVisionActivityMessage(Core.Entities.Activities.VisionActivityMessage aqMessage)
        {
            if (aqMessage.ActivityParams == null){
                aqMessage.ActivityParams = new Entities.Activities.VisionActivityParameterCollection();
            }

            using (Components.ActivityQueueSender queueSender = new Components.ActivityQueueSender(ConfigurationManager.AppSettings["VisionQueue"])){
                queueSender.SendVisionActivityMessage(aqMessage);
            }
        }        
    }
}
